/*
 * @lc app=leetcode.cn id=448 lang=cpp
 *
 * [448] 找到所有数组中消失的数字
 */

// @lc code=start
class Solution
{
public:
  vector<int> findDisappearedNumbers(vector<int>& nums)
  {
    int n = nums.size();
    for (int i = 0; i < n; ++i) {
      if (nums[i] != INT_MIN) {
        int j = nums[i] - 1;
        while (nums[j] != INT_MIN) {
          int next = nums[j] - 1;
          nums[j]  = INT_MIN;
          j        = next;
        }
      }
    }
    vector<int> ans;
    for (int i = 0; i < n; ++i)
      if (nums[i] != INT_MIN)
        ans.push_back(i + 1);
    return ans;
  }
};
// @lc code=end
